{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:40:01.701551300Z",
     "start_time": "2024-07-16T01:40:01.414817Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "    one  two\na  1.40  NaN\nb  7.10 -4.5\nc   NaN  NaN\nd  0.75 -1.3",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>one</th>\n      <th>two</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1.40</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>7.10</td>\n      <td>-4.5</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>0.75</td>\n      <td>-1.3</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=pd.DataFrame([[1.4,np.nan],[7.1,-4.5],\n",
    "                [np.nan,np.nan],[0.75,-1.3]],\n",
    "                index=list('abcd'),\n",
    "                columns=['one','two'])\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:43:29.991317100Z",
     "start_time": "2024-07-16T01:43:29.981909500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "one    9.25\ntwo   -5.80\ndtype: float64"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认按列求和\n",
    "df.sum()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:44:04.715890200Z",
     "start_time": "2024-07-16T01:44:04.705127900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "a     NaN\nb    2.60\nc     NaN\nd   -0.55\ndtype: float64"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按行求和\n",
    "df.sum(axis=1,skipna=False)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:46:36.715534300Z",
     "start_time": "2024-07-16T01:46:36.706314600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "one    b\ntwo    d\ndtype: object"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回最大值的索引\n",
    "df.idxmax()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:47:19.692857500Z",
     "start_time": "2024-07-16T01:47:19.684730800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "    one  two\na  1.40  NaN\nb  8.50 -4.5\nc   NaN  NaN\nd  9.25 -5.8",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>one</th>\n      <th>two</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>a</th>\n      <td>1.40</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>b</th>\n      <td>8.50</td>\n      <td>-4.5</td>\n    </tr>\n    <tr>\n      <th>c</th>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>d</th>\n      <td>9.25</td>\n      <td>-5.8</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumsum()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:47:57.756738700Z",
     "start_time": "2024-07-16T01:47:57.748719400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "            one       two\ncount  3.000000  2.000000\nmean   3.083333 -2.900000\nstd    3.493685  2.262742\nmin    0.750000 -4.500000\n25%    1.075000 -3.700000\n50%    1.400000 -2.900000\n75%    4.250000 -2.100000\nmax    7.100000 -1.300000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>one</th>\n      <th>two</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>3.000000</td>\n      <td>2.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>3.083333</td>\n      <td>-2.900000</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>3.493685</td>\n      <td>2.262742</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>0.750000</td>\n      <td>-4.500000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>1.075000</td>\n      <td>-3.700000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>1.400000</td>\n      <td>-2.900000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>4.250000</td>\n      <td>-2.100000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>7.100000</td>\n      <td>-1.300000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:49:11.854160400Z",
     "start_time": "2024-07-16T01:49:11.843927100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "0     a\n1     a\n2     b\n3     c\n4     a\n5     a\n6     b\n7     c\n8     a\n9     a\n10    b\n11    c\n12    a\n13    a\n14    b\n15    c\ndtype: object"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1=pd.Series(list('aabc')*4)\n",
    "s1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:51:01.582174900Z",
     "start_time": "2024-07-16T01:51:01.574653700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "count     16\nunique     3\ntop        a\nfreq       8\ndtype: object"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-16T01:51:45.645081200Z",
     "start_time": "2024-07-16T01:51:45.638138700Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
